import { constantRoutes } from '@/router/routes'

const permission = {
  state: {
    routes: [],
    addRoutes: [],
    defaultRoutes: [],
    topbarRouters: [],
    sidebarRouters: []
  },
  mutations: {
    SET_ROUTES: (state, routes) => {
      state.addRoutes = routes
      state.routes = constantRoutes.concat(routes)
    },
    SET_DEFAULT_ROUTES: (state, routes) => {
      state.defaultRoutes = constantRoutes.concat(routes)
    },
    SET_TOPBAR_ROUTES: (state, routes) => {
      state.topbarRouters = routes
    },
    SET_SIDEBAR_ROUTERS: (state, routes) => {
      console.log(routes, "routes");

      state.sidebarRouters = routes
    },
  },
  actions: {
    // 现在全部使用前端静态路由，无需异步生成
    GenerateRoutes({ commit }) {
      return new Promise(resolve => {
        commit('SET_ROUTES', [])
        console.log(constantRoutes, "constantRoutes");

        commit('SET_SIDEBAR_ROUTERS', constantRoutes)
        commit('SET_DEFAULT_ROUTES', constantRoutes)
        commit('SET_TOPBAR_ROUTES', constantRoutes)
        resolve(constantRoutes)
      })
    }
  }
}

export default permission
